using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class VariablePanel : MonoBehaviour
{
    RectTransform rectTransform;
    GridLayoutGroup layoutGroup;

    Vector2 oriSize;
    int linecount;
    private void Awake()
    {
        rectTransform = GetComponent<RectTransform>();
        layoutGroup = GetComponent<GridLayoutGroup>();

        oriSize = rectTransform.sizeDelta;
        linecount = (int)(oriSize.x / (layoutGroup.cellSize.x + layoutGroup.spacing.x));
    }

    private void Update()
    {
        float height = (transform.childCount/ linecount + 1) * (layoutGroup.cellSize.y + layoutGroup.spacing.y) + layoutGroup.padding.top + layoutGroup.padding.bottom;
        
        if(height> oriSize.y)
        {
            rectTransform.sizeDelta = new Vector2(oriSize.x, height);
        }
        else
        {
            rectTransform.sizeDelta = oriSize;
        }

    }
}
